import { Message } from 'element-ui'
import { GoLogin } from '@/api'

const actions = {
    async getGoLogin({ commit }, params) {
        const result = await GoLogin(params)
        
        if (result.errno === 0) {
            commit('SAVE_GOLOGIN', result.data)
            localStorage.setItem('TOKEN', result.data.token)
            localStorage.setItem('username', result.data.userInfo.username)
            localStorage.setItem('avatar',result.data.userInfo.avatar)

        } else {
            // ui组件库的弹窗
            Message('密码错误')
            // 如果失败返回一个空的promise，中断链条
            return new Promise(() => { })
        }


    }
};
const mutations = {
    SAVE_GOLOGIN(state, data) {
        state.userInfo = data
    }
};
const state = {
    // 初始化数据
    userInfo: { userInfo: { avatar: '', username: '' } }  //用户信息
};
const getters = {


};
export default {
    namespaced: true,
    actions,
    mutations,
    state,
    getters,
};